<!--
 * @Date: 2024-12-23 14:41:21
 * @LastEditors: Lcx l1556461835@163.com
 * @LastEditTime: 2025-03-24 14:07:39
 * @FilePath: \simulation-fontend\pages\components\RmSim.vue
 * @Description: 粗轧仿真
-->

<template>
  <div>
    <el-card header="PDI参数">
      <el-form :inline="true" :model="tbProcalcSumDTO" label-position="left" label-width="120px">
        <el-form-item label="钢种" prop="steelGrade">
          <el-select v-model="tbProcalcSumDTO.steelGrade" placeholder="钢种" @change="handleSteelChange">
            <el-option v-for="item in steelList" :key="item.id" :label="item.steelGrade" :value="item.steelGrade"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item v-if="flag !== 1" label="入口速度[m/s]"  prop="en_spd">
          <el-input v-model="tbProcalcSumDTO.en_spd" placeholder="入口速度" @input="(v)=>(tbProcalcSumDTO['en_spd'] = v.replace(/[^\d.]/g,''))"></el-input>
        </el-form-item>
        <el-form-item label="成品宽度[mm]" prop="slabWid">
          <el-input v-model="tbProcalcSumDTO.slabWid" placeholder="成品宽度" @change="handleWidChange" @input="(v)=>(tbProcalcSumDTO['slabWid'] = v.replace(/[^\d.]/g,''))"></el-input>
        </el-form-item>
        <el-form-item label="终轧温度[℃]" prop="rm_ex_temp">
          <el-input v-model="tbProcalcSumDTO.rm_ex_temp" placeholder="终轧温度" @input="(v)=>(tbProcalcSumDTO['rm_ex_temp'] = v.replace(/[^\d.]/g,''))"></el-input>
        </el-form-item>
        <el-form-item label="成品厚度[mm]" prop="coilThk">
          <el-input v-model="tbProcalcSumDTO.coilThk" placeholder="成品厚度" @change="handleThkChange" @input="(v)=>(tbProcalcSumDTO['coilThk'] = v.replace(/[^\d.]/g,''))"></el-input>
        </el-form-item>
        <el-form-item label="出口厚度[mm]" prop="rm_ex_thk">
          <el-input v-model="tbProcalcSumDTO.rm_ex_thk" placeholder="出口厚度" @input="(v)=>(tbProcalcSumDTO['rm_ex_thk'] = v.replace(/[^\d.]/g,''))"></el-input>
        </el-form-item>
        <el-form-item label="板坯长度[m]" prop="slabLen">
          <el-input v-model="tbProcalcSumDTO.slabLen" placeholder="板坯长度" @input="(v)=>(tbProcalcSumDTO['slabLen'] = v.replace(/[^\d.]/g,''))"></el-input>
        </el-form-item>
        <el-form-item label="入口厚度[mm]" prop="cc_ST">
          <el-input v-model="tbProcalcSumDTO.cc_ST" placeholder="入口厚度" @input="(v)=>(tbProcalcSumDTO['cc_ST'] = v.replace(/[^\d.]/g,''))"></el-input>
        </el-form-item>
        <el-form-item label="入口温度[℃]" prop="dischtrgtemp">
          <el-input v-model="tbProcalcSumDTO.dischtrgtemp" placeholder="入口温度" @input="(v)=>(tbProcalcSumDTO['dischtrgtemp'] = v.replace(/[^\d.]/g,''))"></el-input>
        </el-form-item>
      </el-form>
    </el-card>
    <!-- 化学元素 -->
    <el-card style="margin: 10px 0">
      <BasicForm :form-list="huaxueList" :form-info="elementDTO" inline></BasicForm>
    </el-card>
    <!-- 工艺设定 -->
    <el-card v-if="flag !== 1" style="margin: 10px 0">
      <div slot="header" class="clearfix">
        <span>工艺设定</span>
        <el-select v-model="tbProcalcSumDTO.versioncode" placeholder="模式" style="float: right; padding: 3px 0; width: 150px">
          <el-option label="1+5" value="1"></el-option>
          <el-option label="3+3" value="2"></el-option>
        </el-select>
      </div>
      <div class="flex">
        <div style="width: 40%">
          <el-table :data="tbProcalcMillDTOS">
            <el-table-column label="道次" prop="mill" align="center"></el-table-column>
            <el-table-column label="压下率" prop="reps" align="center">
              <template slot-scope="scoped">
                <el-input v-model="scoped.row.reps"></el-input>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <el-table :data="setRightTable" height="282px">
          <el-table-column label="道次" prop="mill" align="center"></el-table-column>
          <el-table-column label="传动比" prop="gear" align="center"></el-table-column>
          <el-table-column label="冷却水流量" prop="iscflow" align="center"></el-table-column>
          <el-table-column label="最大轧制力" prop="mrforce" align="center"></el-table-column>
          <el-table-column label="最大开口度" prop="mopening" align="center"></el-table-column>
        </el-table>
      </div>
    </el-card>
    <!-- 规程计算结果 -->
    <el-card v-if="flag == 1"  style="margin: 10px 0">
      <div slot="header" class="clearfix">
        <span>规程计算结果</span>
        <el-select v-model="tbProcalcSumDTO.versioncode" :disabled="true" placeholder="模式" style="float: right; padding: 3px 0; width: 150px">
          <el-option label="1+5" value="1"></el-option>
          <el-option label="3+3" value="2"></el-option>
        </el-select>
      </div>
      <el-table :data="tbSetpointMillVO">
        <el-table-column label="道次" prop="mill" align="center"></el-table-column>
        <el-table-column label="入口厚度" prop="thickentry" align="center"></el-table-column>
        <el-table-column label="出口厚度" prop="thickexit" align="center"></el-table-column>
        <el-table-column label="轧制力(ton)" prop="rollforce" align="center"></el-table-column>
        <el-table-column label="轧制功率" prop="rollpower" align="center"></el-table-column>
        <el-table-column label="入口速度(m/s)" prop="entryspd" align="center"></el-table-column>
        <el-table-column label="出口速度(m/s)" prop="exitspd" align="center"></el-table-column>
      </el-table>
    </el-card>
    <el-card v-if="flag == 1"  header="道次再结晶">
      <el-table :data="tbCrystalstrRollV0">
        <el-table-column label="道次" prop="mill" align="center"></el-table-column>
        <el-table-column label="机架应变" prop="strainRack" align="center"></el-table-column>
        <el-table-column label="真实应变" prop="strainAct" align="center"></el-table-column>
        <el-table-column label="应变速率" prop="strainRate" align="center"></el-table-column>
        <el-table-column label="临界应变" prop="strainCritical" align="center"></el-table-column>
        <el-table-column label="再结晶类型" prop="recryType" align="center"></el-table-column>
        <el-table-column label="形核晶粒尺寸[μm]" prop="nuclGrainSize" align="center"></el-table-column>
        <el-table-column label="50%亚动态/25%静态时间[s]" prop="subDynamicTime50" align="center"></el-table-column>
        <el-table-column label="再结晶分数[%]" prop="grainSize" align="center"></el-table-column>
        <el-table-column label="再结晶残余应变" prop="residualStrain" align="center"></el-table-column>
        <el-table-column label="再结晶晶粒尺寸[μm]" prop="fraction" align="center"></el-table-column>
      </el-table>
    </el-card>
    <el-card v-if="flag == 1" header="组织演变"  style="margin: 10px 0">
      <el-row>
        <el-col :span="6">
          <hmi-echarts :x-axis="tiChart.xAxis" :y-axis="tiChart.yAxis" :series="tiChart.series" :grid="grid" _width="100%"></hmi-echarts>
        </el-col>
        <el-col :span="6">
          <hmi-echarts :legend="chiChart.legend" :x-axis="chiChart.xAxis" :y-axis="chiChart.yAxis" :series="chiChart.series" :grid="grid" _width="100%"></hmi-echarts>
        </el-col>
        <el-col :span="6">
          <hmi-echarts :x-axis="canChart.xAxis" :y-axis="canChart.yAxis" :series="canChart.series" :grid="grid" _width="100%"></hmi-echarts>
        </el-col>
        <el-col :span="6">
          <hmi-echarts :x-axis="tempChart.xAxis" :y-axis="tempChart.yAxis" :series="tempChart.series" :grid="grid" _width="100%"></hmi-echarts>
        </el-col>
      </el-row>
    </el-card>
    <!-- 任务信息 -->
    <el-card header="任务信息">
      <el-form :model="tbProcalcSumDTO" :inline="true">
        <el-form-item label="任务名称" prop="name">
          <el-input v-model="tbProcalcSumDTO.name" placeholder="任务名称"></el-input>
        </el-form-item>
        <el-form-item label="提交人" prop="subPerson">
          <el-input v-model="tbProcalcSumDTO.subPerson" placeholder="提交人"></el-input>
        </el-form-item>
        <el-form-item label="备注" prop="note">
          <el-input v-model="tbProcalcSumDTO.note" placeholder="备注"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button v-if="flag !== 1" type="primary" size="small" @click="submit">提交</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import BasicForm from "../components/BasicForm.vue";
import { FceParams } from "@/lib/commonVar.js";
import { post } from "@/lib/Util";
import HmiEcharts from "../../components/HmiEcharts.vue";
export default {
  components: { BasicForm, HmiEcharts },
  props: {
    formInfo: {
      type: Object,
      default: () => {}
    },
    flag: {
      type: Number,
      default: 0 // 0 新建, 1 查看, 2 编辑
    }
  },
  data() {
    return {
      tbProcalcSumDTO: {
        versioncode: 1,
        rm_ex_thk: undefined
      },
      huaxueList: FceParams,
      elementDTO: {},
      tbProcalcMillDTOS: [
        {
          mill: "R1",
          reps: ""
        },
        {
          mill: "R2",
          reps: ""
        },
        {
          mill: "R3",
          reps: ""
        },
        {
          mill: "R4",
          reps: ""
        },
        {
          mill: "R5",
          reps: ""
        },
        {
          mill: "R6",
          reps: ""
        }
      ],
      steelList: [],
      setRightTable: [],
      tbSetpointMillVO: [], // 规程计算结果
      grid: [
        {
          bottom: 40
        }
      ],
      tiChart: {
        xAxis: [
          {
            type: "category",
            data: [],
            name: "道次"
          }
        ],
        yAxis: [
          {
            type: "value",
            name: "体积分数[%]"
          }
        ],
        series: [
          {
            data: [],
            type: "bar",
            name: "动态再结晶"
          }
        ]
      },
      chiChart: {
        xAxis: [
          {
            type: "category",
            data: [],
            name: "道次"
          }
        ],
        legend: {
          data: [
            {
              name: "晶粒尺寸"
            }
          ],
          show: true
        },
        yAxis: [
          {
            type: "value",
            name: "尺寸[μm]"
          }
        ],
        series: [
          {
            data: [120, 200, 150, 80, 70, 110, 130],
            type: "bar"
          }
        ]
      },
      canChart: {
        xAxis: [
          {
            type: "category",
            data: [],
            name: "道次"
          }
        ],
        yAxis: [
          {
            type: "value",
            name: "残余应变"
          }
        ],
        series: [
          {
            data: [120, 200, 150, 80, 70, 110, 130],
            type: "line",
            name: "残余应变"
          }
        ]
      },
      tempChart: {
        xAxis: [
          {
            type: "category",
            name: "道次",
            data: []
          }
        ],
        yAxis: [
          {
            name: "温度(℃)",
            type: "value"
          },
          {
            name: "晶体尺寸",
            nameLocation: "end",
            type: "value"
          }
        ],
        series: [
          {
            name: "温度",
            type: "line",
            data: []
          },
          {
            name: "尺寸",
            type: "line",
            data: [],
            yAxisIndex: 1
          }
        ]
      },
      tbCrystalstrRollV0: []
    };
  },
  watch: {
    "tbProcalcSumDTO.versioncode": {
      handler(newVal, oldVal) {
        if (newVal) {
          post(`/api/tbMill/post?versionCode=${newVal}&calcType=1`).then(
            res => {
              if (res.data) {
                this.setRightTable = res.data;
              }
            }
          );
        }
      }
    }
  },
  mounted() {
    this.getSteelGrade();
    if (this.flag == 1) {
      console.log(this.formInfo);
      this.tbProcalcSumDTO = this.formInfo.tbProcalcSumVO;
      this.elementDTO = this.formInfo.elementVO;
      this.tbProcalcMillDTOS = this.formInfo.tbProcalcMillVO;
      this.tbSetpointMillVO = this.formInfo.tbSetpointMillVO;
      this.tbCrystalstrRollV0 = this.formInfo.tbCrystalstrRollVO;
      this.getLineData();
    } else if (this.flag == 2) {
      this.tbProcalcSumDTO = this.formInfo.tbProcalcSumVO;
      this.elementDTO = this.formInfo.elementVO;
      this.tbProcalcMillDTOS = this.formInfo.tbProcalcMillVO;
    }
  },
  methods: {
    // 获得曲线数据
    getLineData() {
      if (this.tbCrystalstrRollV0.length) {
        // 第一个图
        let x = [];
        let dong = []; // 暂时只显示动态的
        let jing = [];
        let jingSize = []; // 晶粒尺寸
        let can = []; // 残余应变
        let temp = []; // 温度
        let size = []; // 尺寸
        for (let i = 0; i < this.tbCrystalstrRollV0.length; i++) {
          dong.push(this.tbCrystalstrRollV0[i].recryType);
          x.push(this.tbCrystalstrRollV0[i].mill);
          jingSize.push(this.tbCrystalstrRollV0[i].nuclGrainSize);
          can.push(this.tbCrystalstrRollV0[i].residualStrain);
          temp.push(this.tbCrystalstrRollV0[i].temp);
          size.push(this.tbCrystalstrRollV0[i].nuclGrainSize);
        }
        this.tiChart.xAxis[0].data = x;
        this.tiChart.series[0].data = dong;
        this.chiChart.xAxis[0].data = x;
        this.chiChart.series[0].data = jingSize;
        this.canChart.xAxis[0].data = x;
        this.canChart.series[0].data = can;
        this.tempChart.xAxis[0].data = x;
        this.tempChart.series[0].data = temp;
        this.tempChart.series[1].data = size;
      }
    },
    // 查询钢种
    async getSteelGrade() {
      let res = await post("/api/tbChemical/getSteelGrade", {});
      this.steelList = res.data;
    },
    handleSteelChange(val) {
      if (val) {
        let item = this.steelList.filter(item => item.steelGrade == val);
        post(`/api/tbChemical/byIdSelect?id=${item[0].id}`).then(res => {
          this.elementDTO = res.data;
        });
      } else {
        this.$refs.huaRef.resetForm();
      }
    },
    // 查看设定工艺
    handleWidChange(val) {
      if (val) {
        if (this.tbProcalcSumDTO.coilThk) {
          this.getSet();
        }
      }
    },
    handleThkChange(val) {
      if (val) {
        if (this.tbProcalcSumDTO.slabWid) {
          this.getSet();
        }
      }
    },
    async getSet() {
      let res = await post(
        `/api/tbSchData/selectRoughingCraft?matClass=1&slabThk=${
          this.tbProcalcSumDTO.coilThk
        }&slabWid=${this.tbProcalcSumDTO.slabWid}`
      );
      if (res.data) {
        this.tbProcalcMillDTOS[0].reps = res.data.r1Reps;
        this.tbProcalcMillDTOS[1].reps = res.data.r2Reps;
        this.tbProcalcMillDTOS[2].reps = res.data.r3Reps;
        this.tbProcalcMillDTOS[3].reps = res.data.r4Reps;
        this.tbProcalcMillDTOS[4].reps = res.data.r5Reps;
        this.tbProcalcMillDTOS[5].reps = res.data.r6Reps;
      }
    },
    handleChangeVersion(val) {
      post(`/api/tbMill/post?versionCode=${val}`).then(res => {
        if (res.data) {
          this.setRightTable = res.data;
        }
      });
    },
    // 提交事件
    submit() {
      this.tbProcalcSumDTO["calcType"] = 1; // 标记这是粗轧仿真
      post("/api/tbProcalcSum/roughingSave", {
        tbProcalcSumDTO: this.tbProcalcSumDTO,
        elementDTO: this.elementDTO,
        tbProcalcMillDTOS: this.tbProcalcMillDTOS
      }).then(res => {
        if (res.code == 200) {
          this.$message({
            message: "提交成功",
            type: "success"
          });
        } else {
          this.$message.error(res.message);
        }
        this.$emit("close");
      });
    }
  }
};
</script>

<style>
.flex {
  display: flex;
  width: 100%;
}
</style>
